package com.zzyang.c2c.social.govern.reviewer.service.impl;

import com.zzyang.c2c.social.govern.reviewer.api.ReviewerService;
import com.zzyang.c2c.social.govern.reviewer.dao.ReviewerTaskStatusDAO;
import com.zzyang.c2c.social.govern.reviewer.domain.ReviewerTaskStatus;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;
import java.util.List;

/**
 * TODO
 *
 * @author zhuoziyang
 * @date 2021/7/27 8:20
 */
@Service
public class ReviewerServiceImpl implements ReviewerService {

    @Autowired
    private ReviewerTaskStatusDAO reviewerTaskStatusDAO;

    @Override
    public List<Long> selectReviewers(Long reportTaskId) {
        //选出评审员的id，这里就直接放弃
        List<Long> reviewerIds = new ArrayList<>();
        reviewerIds.add(1L);
        reviewerIds.add(2L);
        reviewerIds.add(3L);
        reviewerIds.add(4L);
        reviewerIds.add(5L);

        for (Long reviewerId : reviewerIds) {
            ReviewerTaskStatus reviewerTaskStatus = new ReviewerTaskStatus();
            reviewerTaskStatus.setReportTaskId(reportTaskId)
                    .setReviewerId(reviewerId)
                    .setStatus(ReviewerTaskStatus.PROCESSING);
            reviewerTaskStatusDAO.add(reviewerTaskStatus);
        }

        return reviewerIds;
    }

    @Override
    public void finishVote(Long reviewerId, Long reportTaskId) {
        ReviewerTaskStatus reviewerTaskStatus = new ReviewerTaskStatus();
        reviewerTaskStatus.setReviewerId(reviewerId)
                .setReportTaskId(reportTaskId)
                .setStatus(ReviewerTaskStatus.FINISHED);

        reviewerTaskStatusDAO.updateStatus(reviewerTaskStatus);
    }

}
